<template>
  <div class="my-counter">
    <button
      type="button"
      class="btn btn-light"
      :disabled="item.goods_count <= 1"
      @click="decreaseFn"
    >
      -
    </button>
    <input
      type="number"
      class="form-control inp"
      v-model.number="item.goods_count"
      @blur="validateFn"
    />
    <button type="button" class="btn btn-light" @click="increaseFn">+</button>
  </div>
</template>

<script>
export default {
  props: {
    item: {
      type: Object,
      required: true,
    },
  },
  //   watch: {
  //     item: {
  //       deep: true,
  //       handler(newVal) {
  //         if (newVal.goods_count <= 1) {
  //           newVal.goods_count = 1;
  //         }
  //       },
  //     },
  //   },
  methods: {
    validateFn() {
      if (this.item.godds_count <= 0) {
        this.item.godds_count = 1;
      }
    },
    decreaseFn() {
      if (this.item.goods_count <= 1) return;
      this.item.goods_count--;
    },
    increaseFn() {
      this.item.goods_count++;
    },
  },
};
</script>  

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>